package com.esms.bean;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for Salaryserviceemployee
 * entities. Transaction control of the save(), update() and delete() operations can directly
 * support Spring container-managed transactions or they can be augmented to handle user-managed
 * Spring transactions. Each of these methods provides additional information for how to configure
 * it for the desired type of transaction control.
 * 
 * @see com.esms.bean.Salaryserviceemployee
 * @author MyEclipse Persistence Tools
 */

public class SalaryserviceemployeeDAO extends BaseHibernateDAO {
	private SalaryserviceemployeeDAO() {}
	public static SalaryserviceemployeeDAO $ = new SalaryserviceemployeeDAO(); 
	
	private static final Log log = LogFactory.getLog(SalaryserviceemployeeDAO.class);
	// property constants
	public static final String FFEMPLOYEE_ID = "ffemployeeId";
	public static final String BASE_WAGE = "baseWage";
	public static final String INSURANCE_BASE = "insuranceBase";
	public static final String HOUSINGFUND_BASE = "housingfundBase";
	public static final String ENDOWMENT_ENTERPRISE = "endowmentEnterprise";
	public static final String MEDICAL_ENTERPRISE = "medicalEnterprise";
	public static final String SUSPENSION_ENTERPRISE = "suspensionEnterprise";
	public static final String WORKPLACE_ENTERPRISE = "workplaceEnterprise";
	public static final String MATERNITY_ENTERPRISE = "maternityEnterprise";
	public static final String HOUSINGFUND_ENTERPRISE = "housingfundEnterprise";
	public static final String HOUSINGFUND_SENTERPRISE = "housingfundSEnterprise";
	public static final String ENDOWMENT_EMPLOYEE = "endowmentEmployee";
	public static final String MEDICAL_EMPLOYEE = "medicalEmployee";
	public static final String SUSPENSION_EMPLOYEE = "suspensionEmployee";
	public static final String WORKPLACE_EMPLOYEE = "workplaceEmployee";
	public static final String MATERNITY_EMPLOYEE = "maternityEmployee";
	public static final String HOUSINGFUND_EMPLOYEE = "housingfundEmployee";
	public static final String HOUSINGFUND_SEMPLOYEE = "housingfundSEmployee";
	public static final String BEFORETAX_SALARY = "beforetaxSalary";
	public static final String INCOMETAX = "incometax";
	public static final String AFTERTAX_SALARY = "aftertaxSalary";

	//add by Jian
	public void insert(Salaryserviceemployee salaryServiceService) {
	    Session session = HibernateSessionFactory.getSession();  
	    Transaction tx = session.beginTransaction();  
	    try {  
	        session.save(salaryServiceService);  
	        tx.commit();  
	    } catch (Exception e) {  
	        tx.rollback();  
	        e.printStackTrace();  
	    }finally{  
	        session.close();  
	    }  
	}
	
	public void save(Salaryserviceemployee transientInstance) {
		log.debug("saving Salaryserviceemployee instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Salaryserviceemployee persistentInstance) {
		log.debug("deleting Salaryserviceemployee instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Salaryserviceemployee findById(java.lang.Integer id) {
		log.debug("getting Salaryserviceemployee instance with id: " + id);
		try {
			Salaryserviceemployee instance = (Salaryserviceemployee) getSession().get(
					"com.esms.bean.Salaryserviceemployee", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Salaryserviceemployee instance) {
		log.debug("finding Salaryserviceemployee instance by example");
		try {
			List results = getSession().createCriteria("com.esms.bean.Salaryserviceemployee").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Salaryserviceemployee instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Salaryserviceemployee as model where model." + propertyName
					+ "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByFfemployeeId(Object ffemployeeId) {
		return findByProperty(FFEMPLOYEE_ID, ffemployeeId);
	}

	public List findByBaseWage(Object baseWage) {
		return findByProperty(BASE_WAGE, baseWage);
	}

	public List findByInsuranceBase(Object insuranceBase) {
		return findByProperty(INSURANCE_BASE, insuranceBase);
	}

	public List findByHousingfundBase(Object housingfundBase) {
		return findByProperty(HOUSINGFUND_BASE, housingfundBase);
	}

	public List findByEndowmentEnterprise(Object endowmentEnterprise) {
		return findByProperty(ENDOWMENT_ENTERPRISE, endowmentEnterprise);
	}

	public List findByMedicalEnterprise(Object medicalEnterprise) {
		return findByProperty(MEDICAL_ENTERPRISE, medicalEnterprise);
	}

	public List findBySuspensionEnterprise(Object suspensionEnterprise) {
		return findByProperty(SUSPENSION_ENTERPRISE, suspensionEnterprise);
	}

	public List findByWorkplaceEnterprise(Object workplaceEnterprise) {
		return findByProperty(WORKPLACE_ENTERPRISE, workplaceEnterprise);
	}

	public List findByMaternityEnterprise(Object maternityEnterprise) {
		return findByProperty(MATERNITY_ENTERPRISE, maternityEnterprise);
	}

	public List findByHousingfundEnterprise(Object housingfundEnterprise) {
		return findByProperty(HOUSINGFUND_ENTERPRISE, housingfundEnterprise);
	}

	public List findByHousingfundSEnterprise(Object housingfundSEnterprise) {
		return findByProperty(HOUSINGFUND_SENTERPRISE, housingfundSEnterprise);
	}

	public List findByEndowmentEmployee(Object endowmentEmployee) {
		return findByProperty(ENDOWMENT_EMPLOYEE, endowmentEmployee);
	}

	public List findByMedicalEmployee(Object medicalEmployee) {
		return findByProperty(MEDICAL_EMPLOYEE, medicalEmployee);
	}

	public List findBySuspensionEmployee(Object suspensionEmployee) {
		return findByProperty(SUSPENSION_EMPLOYEE, suspensionEmployee);
	}

	public List findByWorkplaceEmployee(Object workplaceEmployee) {
		return findByProperty(WORKPLACE_EMPLOYEE, workplaceEmployee);
	}

	public List findByMaternityEmployee(Object maternityEmployee) {
		return findByProperty(MATERNITY_EMPLOYEE, maternityEmployee);
	}

	public List findByHousingfundEmployee(Object housingfundEmployee) {
		return findByProperty(HOUSINGFUND_EMPLOYEE, housingfundEmployee);
	}

	public List findByHousingfundSEmployee(Object housingfundSEmployee) {
		return findByProperty(HOUSINGFUND_SEMPLOYEE, housingfundSEmployee);
	}

	public List findByBeforetaxSalary(Object beforetaxSalary) {
		return findByProperty(BEFORETAX_SALARY, beforetaxSalary);
	}

	public List findByIncometax(Object incometax) {
		return findByProperty(INCOMETAX, incometax);
	}

	public List findByAftertaxSalary(Object aftertaxSalary) {
		return findByProperty(AFTERTAX_SALARY, aftertaxSalary);
	}

	public List findAll() {
		log.debug("finding all Salaryserviceemployee instances");
		try {
			String queryString = "from Salaryserviceemployee";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Salaryserviceemployee merge(Salaryserviceemployee detachedInstance) {
		log.debug("merging Salaryserviceemployee instance");
		try {
			Salaryserviceemployee result = (Salaryserviceemployee) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Salaryserviceemployee instance) {
		log.debug("attaching dirty Salaryserviceemployee instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Salaryserviceemployee instance) {
		log.debug("attaching clean Salaryserviceemployee instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}